Skip to content

fix: reclaim service cache disk usage and prune orphan partitions - #2599

Open
rickkbarbosa wants to merge 3 commits into
ferdium:developfrom
rickkbarbosa:fix/disk-usage
Open

rickkbarbosa wants to merge 3 commits into
ferdium:developfrom
rickkbarbosa:fix/disk-usage

Conversation

@rickkbarbosa

Copy link
Copy Markdown

Motivation

Service webviews keep most of their disk usage outside the HTTP cache. Issue #1814 reports 116 GB in Service Worker / Cache Storage after 2.5 months, and Clear cache did not reclaim it: the button only called session.clearCache(), while CacheStorage and service workers are cleared by a different API.

Measured on a fresh profile with four services (WhatsApp, Telegram, Slack, Gmail):

  • after load: 42 MB total, WhatsApp 28 MB (16 MB service worker + 9.4 MB HTTP cache)
  • clearCache() only (current behaviour): 23 MB
  • clearStorageData({cachestorage,serviceworkers,shadercache}) only: 26 MB
  • both: 6.7 MB (-84%)

Integration run against the built handler on a service partition: 27.6 MB -> 2.4 MB (-91%), with IndexedDB and cookies preserved.

Changes

  1. src/helpers/partition-helpers.ts (new): resolves whether a service lives in its sandbox partition or its own, validates persistent partition names received over IPC, and detects orphan partition directories. Pure functions, unit-tested.
  2. clear-cache resolves the partition sent by the renderer, validates it in the main process, and clears the HTTP cache and cachestorage / serviceworkers / shadercache. Cookies, localStorage and IndexedDB are untouched, so clearing the cache no longer logs the user out or discards the message database.
  3. clear-storage-data accepts the same partition (used by service deletion).
  4. Service deletion removes the partition of the service and, when it was the last service in the group, the sandbox partition. Shared sandboxes are kept.
  5. Orphan sweep on startup: a reaction on the services list runs once when the list is available, and never against an empty list (that also happens when the API call fails and would delete valid partitions).
  6. Clear all cache uses the same orphan detection, so sandbox partitions are covered too.

Verification

  • pnpm test: 18 suites / 161 tests (19 new)
  • pnpm typecheck: pass
  • pnpm lint (--max-warnings 0): pass
  • AppImage builds and starts

Risk

  • Services reload their assets on the next open (expected) and keep their session.
  • IndexedDB is no longer cleared by Clear cache; that destructive path stays on service deletion. This is a deliberate behaviour change from fix: clear service browser storage before reload or deletion #2512 worth a second opinion: clearing IndexedDB logs users out of WhatsApp/Slack and does not reclaim meaningful space.

Fixes #2569. Refs #1814.

Gabi added 3 commits October 21, 2026 23:51
The service webview keeps most of its disk usage outside the HTTP cache: CacheStorage and service workers are cleared by a different API, so clear-cache only reclaimed a fraction of the space it reported. Resolve the service partition (sandbox or standalone) in the renderer, validate it in the main process, and clear the HTTP cache plus cachestorage/serviceworkers/shadercache. Cookies, localStorage and IndexedDB are kept, so clearing the cache no longer logs the user out or drops the message database.
Deleting a service that lives in a sandbox partition removed persist:service-<id>, which does not exist, and left persist:sandbox-<id> behind. A service deleted on another machine (sync) was never swept either. Resolve the partition of the deleted service, drop the sandbox partition when it was the last service in the group, and run the orphan sweep on startup once the service list is available (never against an empty list, which also happens when the API fails).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Orphaned partitions can still occur in certain situations

1 participant